import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/tour_product";

export const buy_info_api = (
  data: { product_id: string },
  showError = true
) => {
  return Http.get<any>(`/v3${baseUrl}/buy_info`, data).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const buy_info_select_day_api = (
  data: { product_id: string },
  showError = true
) => {
  return Http.get<{ select_day: any[] }>(
    `/v3${baseUrl}/buy_info_select_day`,
    data
  ).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const get_specs_list_api = (
  data: { product_id: string; date: string },
  showError = true
) => {
  return Http.get<{ items: any[] }>(`/v2${baseUrl}/get_specs_list`, data).catch(
    error => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const get_specs_date_list_api = (
  data: { product_id: string; specs_id: string },
  showError = true
) => {
  return Http.get<{ items: any[] }>(
    `/v2${baseUrl}/get_specs_date_list`,
    data
  ).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const order_set_api = (
  data: { specs_id: string; use_date: string },
  showError = true
) => {
  return Http.get<any>(`/v2${baseUrl}/order_set`, data).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const get_max_specs_api = (
  data: { specs_id: string; use_date: string; count: number },
  showError = true
) => {
  return Http.get<any>(`/v2${baseUrl}/get_max_specs`, data).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
